from enum import Enum
from typing import List, Optional
import uuid


class SequenceStatus(Enum):
    WAITING = "waiting"
    RUNNING = "running"
    FINISHED = "finished"
    FAILED = "failed"


class Sequence:
    """序列管理类"""

    def __init__(self, request_id: str, prompt: str, prompt_token_ids: List[int]):
        self.request_id = request_id
        self.prompt = prompt
        self.prompt_token_ids = prompt_token_ids
        self.token_ids = prompt_token_ids.copy()
        self.status = SequenceStatus.WAITING
        self.block_table: List[int] = []
        self.output_text = ""
        self.output_token_ids: List[int] = []

    def append_token(self, token_id: int, token_text: str):
        """添加生成的token"""
        self.output_token_ids.append(token_id)
        self.output_text += token_text
        self.token_ids.append(token_id)

    def is_finished(self) -> bool:
        """检查是否完成"""
        return self.status == SequenceStatus.FINISHED

    def get_len(self) -> int:
        """获取序列长度"""
        return len(self.token_ids)